<%--
  Created by IntelliJ IDEA.
  User: longl
  Date: 2020/8/196
  Time: 19:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="basePath.jsp"%>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>ProClinic-医院管理系统Bootstrap4前端框架</title>
    <!-- Fav  Icon Link -->
    <link rel="shortcut icon" type="image/png" href="${basePath}afsets/images/fav.png">
    <!-- Bootstrap core CSS -->
    <link rel="stylesheet" href="${basePath}afsets/css/bootstrap.min.css">
    <!-- themify icons CSS -->
    <link rel="stylesheet" href="${basePath}afsets/css/themify-icons.css">
    <!-- Animations CSS -->
    <link rel="stylesheet" href="${basePath}afsets/css/animate.css">
    <!-- Main CSS -->
    <link rel="stylesheet" href="${basePath}afsets/css/styles.css">
    <link rel="stylesheet" href="${basePath}afsets/css/green.css" id="style_theme">
    <link rel="stylesheet" href="${basePath}afsets/css/responsive.css">
    <!-- morris charts -->
    <link rel="stylesheet" href="${basePath}afsets/charts/css/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="${basePath}afsets/css/jquery-jvectormap.css">
    <link rel="stylesheet" href="${basePath}afsets/datatable/dataTables.bootstrap4.min.css">

    <script src="${basePath}afsets/js/modernizr.min.js"></script>
</head>

<body>
<!-- Pre Loader -->
<div class="loading">
    <div class="spinner">
        <div class="double-bounce1"></div>
        <div class="double-bounce2"></div>
    </div>
</div>
<!--/Pre Loader -->
<!-- Color Changer -->
<div class="theme-settings" id="switcher">
		<span class="theme-click">
			<span class="ti-settings"></span>
		</span>
    <span class="theme-color theme-default theme-active" data-color="green"></span>
    <span class="theme-color theme-blue" data-color="blue"></span>
    <span class="theme-color theme-red" data-color="red"></span>
    <span class="theme-color theme-violet" data-color="violet"></span>
    <span class="theme-color theme-yellow" data-color="yellow"></span>
</div>
<!-- /Color Changer -->
<div class="wrapper">
    <!-- Page Content -->
    <div id="content">
        <!-- Top Navigation -->
        <div class="container top-brand">
            <nav class="navbar navbar-default">
                <div class="navbar-header">
                    <div class="sidebar-header"> <a href="index.html"><img src="${basePath}afsets/images/logo-dark.png" class="logo" alt="logo"></a>
                    </div>
                </div>
                <ul class="nav justify-content-end">
                    <%@include file="loginOut_head.jsp"%>
                </ul>

            </nav>
        </div>
        <!-- /Top Navigation -->
        <!-- Menu -->
        <div class="container menu-nav">
            <nav class="navbar navbar-expand-lg lochana-bg text-white">
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
                        aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="ti-menu text-white"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav mr-auto">
                        <%@include file="headHTML.jsp"%>
                    </ul>
                </div>
            </nav>
        </div>
        <!-- /Menu -->
        <!-- Breadcrumb -->
        <!-- Page Title -->
        <div class="container mt-0">
            <div class="row breadcrumb-bar">
                <div class="col-md-6">
                    <h3 class="block-title">Add 医生</h3>
                </div>
                <div class="col-md-6">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item">
                            <a href="index.html">
                                <span class="ti-home"></span>
                            </a>
                        </li>
                        <li class="breadcrumb-item">医生s</li>
                        <li class="breadcrumb-item active">Add 医生</li>
                    </ol>
                </div>
            </div>
        </div>
        <!-- /Page Title -->

        <!-- /Breadcrumb -->
        <!-- Main Content -->
        <div class="container">

            <div class="row">
                <!-- Widget Item -->
                <div class="col-md-12">
                    <div class="widget-area-2 lochana-box-shadow">
                        <h3 class="widget-title">Add 医生</h3>
                        <div id="tips-date" class="tips-date"></div>
                        <form action="/doctor/add_doctor" method="post" enctype="multipart/form-data" onsubmit="return checkAll()">
                            <div class="form-row">
                                <div class="form-group col-md-6">
                                    <label for="医生-name">医生姓名</label>
                                    <input type="text" class="form-control" placeholder="请输入中文名" id="医生-name" name="dname" onblur="checkName()" />
                                    <span  style="font-size:13px" id="name_span"></span>
                                </div>
                                <div class="form-group col-md-6">
                                    <label for="dob">出生日期</label>
                                    <input type="date" placeholder="选择出生日期" class="form-control" id="dob" name="age"/>
                                </div>
                                <div class="form-group col-md-6">
                                    <label for="specialization">挂号费</label>
                                    <input type="text" placeholder="输入金额" class="form-control" id="specialization" name="price" onblur="checkPrice()" />
                                    <span  style="font-size:13px" id="price_span"></span>
                                </div>
                                <div class="form-group col-md-6">
                                    <label for="room-type">性别</label>
                                    <select class="form-control" id="room-type" name="sex">
                                        <option>男</option>
                                        <option>女</option>
                                    </select>
                                </div>
                                <div class="form-group col-md-6">
                                    <label for="phone">Phone</label>
                                    <input type="text" placeholder="Phone" class="form-control" id="phone" name="tel" onblur="checkTel()" />
                                    <span  style="font-size:13px" id="tel_span"></span>
                                </div>
                                <div class="form-group col-md-6">
                                    <label for="room-type">科室</label>
                                    <select class="form-control" id="" name="deptid">
                                        <c:forEach items="${departments}" var="department">
                                            <option value="${department.id}">${department.deptName}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                                <div class="form-group col-md-6">
                                    <label for="about-doctor">医生描述</label>
                                    <textarea placeholder="医生 Details" class="form-control" id="about-doctor" rows="3" name="resume"></textarea>
                                </div>
                                <div class="form-group col-md-12">
                                    <label for="file">照片</label>
                                    <input type="file" class="form-control" id="file" name="file">
                                </div>
                                <div class="form-group col-md-6 mb-3">
                                    <button type="submit" class="btn btn-primary btn-lg">提交</button>
                                </div>
                            </div>
                        </form>

                        <!-- /Alerts-->
                    </div>
                </div>
                <!-- /Widget Item -->
            </div>
        </div>
        <!-- /Main Content -->
    </div>
    <!-- /Page Content -->
</div>
<!-- Jquery Library-->
<script src="${basePath}afsets/js/jquery-3.2.1.min.js"></script>
<!-- Popper Library-->
<script src="${basePath}afsets/js/popper.min.js"></script>
<!-- Bootstrap Library-->
<script src="${basePath}afsets/js/bootstrap.min.js"></script>

<!-- Datatable  -->
<script src="${basePath}afsets/datatable/jquery.dataTables.min.js"></script>
<script src="${basePath}afsets/datatable/dataTables.bootstrap4.min.js"></script>

<!-- Custom Script-->
<script src="${basePath}afsets/js/custom.js"></script>

<script>
    var strs_data = "";
    var name_zz = /^[\u4e00-\u9fa5]+$/;
    var tel_zz = /^1[3456789]\d{9}$/;
    var price_zz = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;

    function checkName(){
        var doctor_name = $("input[name='dname']").val();
        var spanNode = document.getElementById("name_span");
        if(name_zz.test(doctor_name)){
            //符合规则
            spanNode.innerHTML = "".fontcolor("green");
            return true;
        }else{
            //不符合规则
            spanNode.innerHTML = "*昵称只能为中文，不可以使用其他符号、字母、数字".fontcolor("red");
            return false;
        }
    }

    function checkPrice() {
        var price = $("input[name='price']").val();
        var spanNode = document.getElementById("price_span");
        if(price_zz.test(price)){
            //符合规则
            spanNode.innerHTML = "".fontcolor("green");
            return true;
        }else{
            //不符合规则
            spanNode.innerHTML = "*只能填写大于0的数字".fontcolor("red");
            return false;
        }
    }


    function checkTel() {
        var tel = $("input[name='tel']").val();
        var spanNode = document.getElementById("tel_span");
        if(tel_zz.test(tel)){
            //符合规则
            spanNode.innerHTML = "".fontcolor("green");
            return true;
        }else{
            //不符合规则
            spanNode.innerHTML = "*请填写正确格式的电话号码".fontcolor("red");
            return false;
        }
    }

    function checkDate() {
        var tel = $("input[name='age']").val();
        var spanNode = document.getElementById("tel_span");
        var day2 = new Date();
        day2.setTime(day2.getTime());
        var s2 = day2.getFullYear()+"-" + (day2.getMonth()+1) + "-" + day2.getDate();
        alert("age="+age+",day2="+day2);
        if(tel_zz.test(tel)){
            //符合规则
            spanNode.innerHTML = "".fontcolor("green");
            return true;
        }else{
            //不符合规则
            spanNode.innerHTML = "*日期不可大于今天".fontcolor("red");
            return false;
        }
    }
    
    function checkAll() {
        var age = $("input[name='age']").val();
        var day = age.substring(age.length-2,age.length);
        var month = age.substring(5,7);
        var year = age.substring(0,4);
        var day2 = new Date();
        day2.setTime(day2.getTime());
        var dname = $("input[name='dname']").val();
        var tel = $("input[name='tel']").val();
        var price = $("input[name='price']").val();
        var resume = $("input[name='resume']").val();
        var file = $("input[name='file']").val();
        var price_flag = checkPrice();
        var name_flag = checkName();
        var tel_flag = checkTel();
        if (age==""||dname==""||tel==""||price==""||resume==""||file==""){
            $(".tips-date").html("");
            strs_data = "";
            strs_data+='<div class="alert alert-warning" role="alert">';
            strs_data+='                   数据未填写完整';
            strs_data+='</div>';
            $(".tips-date").html(strs_data);
            return false;
        }else if(year>day2.getFullYear()){
            date_strs(strs_data);
            return false;
        } else if (year==day2.getFullYear()){
            if (month>day2.getMonth()+1){
                date_strs(strs_data);
                return false;
            }else if (month==day2.getMonth()+1){
                if (day>=day2.getDate()){
                    date_strs(strs_data);
                    return false;
                }
            }
        }
           if(price_flag&&name_flag&&tel_flag) {
            $(".tips-date").html("");
            strs_data = "";
            strs_data+='<div class="alert alert-warning" role="alert">';
            strs_data+='                   添加成功，正在回到选择科室页面';
            strs_data+='</div>';
            $(".tips-date").html(strs_data);
            setTimeout(function() {
                return true;
            }, 1000);
        }else {
            return false;
        }
    }

    function date_strs(strs_data) {
        $(".tips-date").html("");
        strs_data = "";
        strs_data+='<div class="alert alert-warning" role="alert">';
        strs_data+='                   出生日期不可大于等于今天';
        strs_data+='</div>';
        $(".tips-date").html(strs_data);
    }
</script>
</body>

</html>
